<template>
  <el-dialog
    v-model="dialogFormVisible"
    :title="title"
    width="800px"
    @close="close"
  >
    <el-form ref="formRef" label-width="80px" :model="form" :rules="rules">
      <el-row :gutter="15">
        <el-space>
          <el-col>
            <el-form-item label="工单编号" prop="title">
              <el-input v-model="form.title" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="派单日期" prop="title">
              <el-input v-model="form.title" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="完成日期" prop="title">
              <el-input v-model="form.title" />
            </el-form-item>
          </el-col>
        </el-space>
      </el-row>
      <el-row :gutter="15">
        <el-space>
          <el-col>
            <el-form-item label="店铺ID" prop="title">
              <el-input v-model="form.title" />
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="选择产品" prop="title">
              <el-select>
                <el-option>请选择产品</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="指派视频人员" prop="title">
              <el-select>
                <el-option />
              </el-select>
            </el-form-item>
          </el-col>
        </el-space>
      </el-row>
    </el-form>

    <template #footer>
      <vab-query-form>
        <vab-query-form-left-panel :span="12">
          <el-space>
            <el-form-item label="任务内容">
              <el-cascader
                v-model="selectProduct"
                :options="productOption"
                width="200"
                @change="handleSelectProduct"
              />
            </el-form-item>
            <el-form-item label="单位">
              <el-select />
            </el-form-item>
            <el-form-item label="计划数量">
              <el-input width="200" />
            </el-form-item>
            <el-form-item>
              <el-button :icon="Search" type="primary" @click="queryData">
                确认添加
              </el-button>
            </el-form-item>
          </el-space>
        </vab-query-form-left-panel>
        <vab-query-form-right-panel :span="12">
          <el-button @click="close">取 消</el-button>
          <el-button type="primary" @click="save">确 定</el-button>
        </vab-query-form-right-panel>
      </vab-query-form>
    </template>
    <el-table
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column
        align="center"
        label="任务内容"
        prop="OrderID"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="单位"
        prop="BusinessClassID"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="计划数量"
        prop="OrderState"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="制作周期"
        prop="OrderState"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="实际数量"
        prop="OrderState"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="备注"
        prop="OrderState"
        show-overflow-tooltip
      />
    </el-table>
  </el-dialog>
</template>

<script>
  import { doTrusteeship } from '@/api/businessOrderCreate'

  export default defineComponent({
    name: 'AssignVideoer',
    emits: ['fetch-data'],
    setup(props, { emit }) {
      const $baseMessage = inject('$baseMessage')

      const state = reactive({
        formRef: null,
        form: {
          roles: [],
        },
        rules: {
          title: [{ required: true, trigger: 'blur', message: '请输入标题' }],
        },
        title: '',
        dialogFormVisible: false,
      })

      const showEdit = (row) => {
        if (!row) {
          state.title = '分单到视频主管'
        } else {
          state.title = '分单到视频主管'
          state.form = Object.assign({}, row)
        }
        state.dialogFormVisible = true
      }
      const close = () => {
        state['formRef'].resetFields()
        state.form = {
          roles: [],
        }
        state.dialogFormVisible = false
      }
      const save = () => {
        state['formRef'].validate(async (valid) => {
          if (valid) {
            const { msg } = await doTrusteeship(state.form)
            $baseMessage(msg, 'success', 'vab-hey-message-success')
            emit('fetch-data')
            close()
          }
        })
      }

      return {
        ...toRefs(state),
        showEdit,
        close,
        save,
      }
    },
  })
</script>
